package edu.hawaii.halealohacli.command;

import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertEquals; 
import javax.xml.datatype.XMLGregorianCalendar;
import org.junit.Test;
import org.wattdepot.client.WattDepotClient;
import org.wattdepot.resource.source.jaxb.Source;
import org.wattdepot.util.tstamp.Tstamp;

/**
 * Tests the SetBaseline class to ensure that it properly stores baseline values.
 * 
 * @author Branden Ogata
 *
 */

public class TestSetBaseline {

  /**
   * Executes printResults to store data, then tests getBaselineData.
   * Since exceptions are handled in the HaleAlohaClientUI class,
   * it is very difficult to test invalid input here; 
   * thus we assume that the exception handling elsewhere works properly.
   * 
   * @throws Exception  Handles any errors that do occur.
   */
  
  @Test
  public void test() throws Exception {
    // A SetBaseline object to test
    SetBaseline setBaseline = new SetBaseline();
    
    // Various data necessary for testing
    WattDepotClient client = new WattDepotClient("http://server.wattdepot.org:8190/wattdepot/");
    Source sourceIlima = client.getSource("Ilima");
    Source sourceMokihana = client.getSource("Mokihana");
    Source sourceLehua = client.getSource("Lehua-A");
    Source sourceLokelani = client.getSource("Lokelani-B"); 
    XMLGregorianCalendar testTimestamp = Tstamp.makeTimestamp();
    testTimestamp.setYear(2011);
    testTimestamp.setMonth(12);
    testTimestamp.setDay(1);
    testTimestamp.setHour(0);
    testTimestamp.setMinute(0);
    testTimestamp.setSecond(0);
    testTimestamp.setMillisecond(0);    
    
    // Sets up a few Baseline objects within setBaseline
    setBaseline.printResults(client, sourceIlima, testTimestamp);
    setBaseline.printResults(client, sourceMokihana, testTimestamp);
    setBaseline.printResults(client, sourceLehua, testTimestamp);
    setBaseline.printResults(client, sourceLokelani, testTimestamp); 
    
    // Tests for valid data for valid input
    for (int i = 0; i < 23; i++) {
      assertNotSame("Check Ilima Baseline", setBaseline.getBaselineData("Ilima")[i], -1.0);
    }
    // Tests for invalid input
    assertEquals("Check Nonexistent Baseline", setBaseline.getBaselineData("Alpha")[0], -1.0, 0.0);
  }

}
